package com.wellsantos.dgwt.home.client.view;

import com.google.gwt.dom.client.Document;
import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HorizontalSplitPanel;
import com.google.gwt.user.client.ui.Widget;
import com.googlecode.dgwt.client.dijit.Dijit;
import com.googlecode.dgwt.client.dijit.HTML;
import com.googlecode.dgwt.client.dijit.layout.ScrollPanel;
import com.googlecode.dgwt.client.dijit.layout.VFlexPanel;
import com.googlecode.dgwt.client.dojo.Dojo;
import com.wellsantos.dgwt.client.view.MainViewBase;
import com.wellsantos.dgwt.client.view.MenuViewBase;

public class HomeView extends BaseView implements MainViewBase {

    private VFlexPanel mainPanel = new VFlexPanel();
    private VFlexPanel menuPanel = new VFlexPanel();
    private VFlexPanel bodyPanel = new VFlexPanel();

    private HorizontalSplitPanel mainStruct = new HorizontalSplitPanel();
    
    private HTML bodyTitle = new HTML("<h4></h4>");
    private ScrollPanel bodyContent = new ScrollPanel();
    
    
    private MenuView menuView = new MenuView();
    
    
    @Override
    public void onShow() {
        Document.get().getBody().getStyle().setProperty("overflow", "hidden");
        super.onShow();
    }


    @Override
    public void onHide() {
        Document.get().getBody().getStyle().setProperty("overflow", "");
        super.onHide();
    }


    public HomeView(){
        Widget widget;

        menuPanel.setWidth("100%");
        menuPanel.add(widget = new HTML("<h4>"+menuView.getTitle()+"</h4>"));
        menuPanel.add(menuView.getWidget(), 1);
        menuPanel.setCellHorizontalAlignment(widget, HasHorizontalAlignment.ALIGN_CENTER);
        Dojo.addClass(menuPanel.getWidgetTd(widget), "dijitToolbar");
        
        bodyPanel.add(bodyTitle);
        bodyPanel.add(bodyContent, 1);
        bodyPanel.setWidth("100%");
        bodyContent.setWidth("100%");		
        bodyPanel.setCellHorizontalAlignment(bodyTitle, HasHorizontalAlignment.ALIGN_CENTER);
        Dojo.addClass(bodyPanel.getWidgetTd(bodyTitle), "dijitToolbar");

        
        mainStruct.add(menuPanel);
        mainStruct.add(bodyPanel);
        mainStruct.setSplitPosition("180px");

        Dijit.getTheme().dijitBorderPanel().applyTo(menuPanel, bodyPanel);
        Dojo.setStyle(bodyPanel.getElement().getParentElement(), "overflow", "hidden");
        Dojo.setStyle(menuPanel.getElement().getParentElement(), "overflow", "hidden");

        mainPanel.setSpacing(10);
        mainPanel.setWidth("100%");
        mainPanel.add(new HTML("<h3 style='margin:5px'>"+MESSAGE_RESOURCES.windowTitle()+"</h3>"));		
        mainPanel.add(mainStruct, 1);
    }
    
    
    @Override
    public void setContent(Widget content, String label){
        bodyContent.clear();
        bodyContent.add(content);
        bodyTitle.setText(label);
    }

    
    @Override
    public Widget getWidget() {
        return mainPanel;
    }


    @Override
    public String getTitle() {
        return MESSAGE_RESOURCES.windowTitle();
    }

    @Override
    public MenuViewBase getMenuView() {
        return menuView;
    }

}
